#################################################
#
# Makefile progetto lso 2011
# (fram 1)(fram 2)(fram 3)
#################################################


# ***** DA COMPLETARE ******  con i file da consegnare *.c e *.h                                                                       
# primo frammento                                                                                                           
FILE_DA_CONSEGNARE1= dgraph.c shortestpath.c

# secondo frammento                                                                                                         
FILE_DA_CONSEGNARE2=

# terzo frammento                                                                                                          
FILE_DA_CONSEGNARE3=

# Compilatore
CC= gcc
# Flag di compilazione
CFLAGS = -Wall -pedantic -g 

# Librerie 
# Directory in cui si trovano le librerie
LIBDIR = ../lib
# Opzione di linking
LIBS = -L $(LIBDIR)

# Nome libreria primo frammento
LIBNAME1 = libcars.a
# Oggetti libreria $(LIBNAME1)
# DA COMPLETARE se si usano piu' file in aggiunta da dgraph.o
objects1 = dgraph.o shortestpath.o 


# Nome eseguibili primo frammento
exe1 = dgraph
exe2 = shpath




.PHONY: clean lib1 test11 test12 consegna1 docu


# creazione libreria primo frammento
lib1:  $(objects1)
	-rm  -f $(LIBDIR)/$(LIBNAME1)
	ar -r $(LIBNAME1) $(objects1)
	cp $(LIBNAME1) $(LIBDIR)



# eseguibili test primo frammento
$(exe1) : test-dgraph.o
	$(CC) -o $@ $^ $(LIBS) -lcars

$(exe2) : test-shpath.o
	$(CC) -o $@ $^ $(LIBS) -lcars

test-dgraph.o: test-dgraph.c dgraph.h
	$(CC) $(CFLAGS) -c $<

test-shpath.o: test-shpath.c dgraph.h shortestpath.h
	$(CC) $(CFLAGS) -c $<

# make rule per gli altri .o del primo frammento (***DA COMPLETARE***)








########### NON MODIFICARE DA QUA IN POI ################
# genera la documentazione con doxygen
docu: ../doc/Doxyfile
	make -C ../doc/

#ripulisce  l'ambiente
clean:
	-rm -f *.o *~ ./core 


# target di test del primo frammento
F=./TUSCANY.map ./CITY.txt
test11: 
	make clean
	make lib1
	make $(exe1)
	cp ./DATA/CITY.txt ./DATA/TUSCANY.map .
	chmod 644 ./CITY.txt ./TUSCANY.map
	@echo MALLOC_TRACE=$(MALLOC_TRACE)
	@echo MALLOC_TRACE deve essere settata a \"./.mtrace.log\"
	-rm -f ./.mtrace.log
	./$(exe1) 
	mtrace ./$(exe1) ./.mtrace.log
	sort ./outcitta.txt > ./outcitta.sort
	sort ./outstrade.map > ./outstrade.sort
	sort ./CITY.txt > ./CITY.sort
	sort ./TUSCANY.map > ./TUSCANY.sort
	diff ./CITY.sort ./outcitta.sort
	diff ./TUSCANY.sort ./outstrade.sort
	@echo  -e "\a\n\t **** Test 11 superato! ****\n"

test12: 
	make clean
	make lib1
	make $(exe2)
	cp ./DATA/out12.check .
	chmod 644 ./out12.check
	rm -f ./out12
	@echo MALLOC_TRACE=$(MALLOC_TRACE)
	@echo MALLOC_TRACE deve essere settata a \"./.mtrace.log\"
	-rm -f ./.mtrace.log
	./$(exe2) > ./out12
	diff ./out12 ./out12.check
	mtrace ./$(exe2) ./.mtrace.log
	@echo -e  "\a\n\t **** Test 12 superato! ****\n"

# target di consegna del primo frammento
SUBJECT1="lso11: consegna primo frammento"
ADDRESS="susanna@di.unipi.it"
#effettua il test e prepara il tar per la consegna
consegna1:
	make clean
	make test11
	make test12
	./gruppo-check.pl < gruppo.txt
	tar -cvf $(USER)-f1.tar ./gruppo.txt $(FILE_DA_CONSEGNARE1) ./Makefile
	@echo -e "*** PRIMO FRAMMENTO: TAR PRONTO $(USER)-f1.tar ***"
	@echo -e "*** inviare per email a $(ADDRESS) con subject\n \"$(SUBJECT1)\" ***"

